﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.Configuration;
using System.Data;
using System.Diagnostics;
using MySql;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Security.Principal;

namespace doris.Admin {
    public partial class ServiceAgreement : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            if (Request.QueryString["id"] == null) {
//                DetailsView1.ChangeMode(DetailsViewMode.Insert);
            }

        }

        protected void bAction_Click(object sender, EventArgs e) {
            MySqlConnection conn = new MySqlConnection(WebConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString);
            try {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;
                // CREATE PROCEDURE `Doris`.`storeServiceAgreement` (IN in_serviceagreementid int(11), IN in_serviceid int(11), IN in_companyid int(11), IN in_configurationmailid int(11))

                cmd.CommandText = "addServiceAgreement";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new MySqlParameter("@in_serviceid", MySqlDbType.Int32));
                cmd.Parameters["@in_serviceid"].Value = ddService.SelectedValue;
                cmd.Parameters["@in_serviceid"].Direction = ParameterDirection.Input;

                cmd.Parameters.Add(new MySqlParameter("@in_configurationmailid", MySqlDbType.Int32));
                cmd.Parameters["@in_configurationmailid"].Value = ddConfigMail.SelectedValue;
                cmd.Parameters["@in_configurationmailid"].Direction = ParameterDirection.Input;

                cmd.Parameters.Add(new MySqlParameter("@in_companyid", MySqlDbType.Int32));
                cmd.Parameters["@in_companyid"].Value = ddCompany.SelectedValue;
                cmd.Parameters["@in_companyid"].Direction = ParameterDirection.Input;

                cmd.ExecuteNonQuery();

                cmd.Dispose();
            } catch (MySql.Data.MySqlClient.MySqlException ex) {
                Debug.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            } finally {
                conn.Close();
            }
            Response.Redirect("ServiceAgreements.aspx");
            
        }
  /*      protected void GetServices() {
            MySqlConnection conn = new MySqlConnection(WebConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString);
            try {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;

                cmd.CommandText = "getAllServices";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new MySqlParameter("@in_ticketdataid", MySqlDbType.Int32));
                cmd.Parameters["@in_ticketdataid"].Value = int.Parse(Request.QueryString["d"]);
                cmd.Parameters["@in_ticketdataid"].Direction = ParameterDirection.Input;

                cmd.Parameters.Add(new MySqlParameter("@out_ticketid", MySqlDbType.Int32));
                cmd.Parameters["@out_ticketid"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_createddate", MySqlDbType.DateTime));
                cmd.Parameters["@out_createddate"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_updateddate", MySqlDbType.DateTime));
                cmd.Parameters["@out_updateddate"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_title", MySqlDbType.VarChar));
                cmd.Parameters["@out_title"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_message", MySqlDbType.Text));
                cmd.Parameters["@out_message"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_ticketdatatypeid", MySqlDbType.Int32));
                cmd.Parameters["@out_ticketdatatypeid"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_type", MySqlDbType.VarChar));
                cmd.Parameters["@out_type"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_workminutes", MySqlDbType.VarChar));
                cmd.Parameters["@out_workminutes"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_agentid", MySqlDbType.VarChar));
                cmd.Parameters["@out_agentid"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_tickedassignedid", MySqlDbType.Int32));
                cmd.Parameters["@out_tickedassignedid"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_parentticketdataid", MySqlDbType.Int32));
                cmd.Parameters["@out_parentticketdataid"].Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                objMessage.Text = "<pre>" + cmd.Parameters["@out_message"].Value.ToString() + "</pre>";

                lnkReply.NavigateUrl = "Reply.aspx?id=" + Request.QueryString["id"] + "&d=" + Request.QueryString["d"];
                cmd.Dispose();
            } catch (MySql.Data.MySqlClient.MySqlException ex) {
                Debug.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            } finally {
                conn.Close();
            }
        }

        protected void GetServices() {
            MySqlConnection conn = new MySqlConnection(WebConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString);
            try {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;

                cmd.CommandText = "getAllServices";
                cmd.CommandType = CommandType.StoredProcedure;

                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read()) {
                    
                }
                cmd.Dispose();
            } catch (MySql.Data.MySqlClient.MySqlException ex) {
                Debug.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            } finally {
                conn.Close();
            }
        }

        protected void GetServices() {
            MySqlConnection conn = new MySqlConnection(WebConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString);
            try {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = conn;

                cmd.CommandText = "getAllServices";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new MySqlParameter("@in_ticketdataid", MySqlDbType.Int32));
                cmd.Parameters["@in_ticketdataid"].Value = int.Parse(Request.QueryString["d"]);
                cmd.Parameters["@in_ticketdataid"].Direction = ParameterDirection.Input;

                cmd.Parameters.Add(new MySqlParameter("@out_ticketid", MySqlDbType.Int32));
                cmd.Parameters["@out_ticketid"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_createddate", MySqlDbType.DateTime));
                cmd.Parameters["@out_createddate"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_updateddate", MySqlDbType.DateTime));
                cmd.Parameters["@out_updateddate"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_title", MySqlDbType.VarChar));
                cmd.Parameters["@out_title"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_message", MySqlDbType.Text));
                cmd.Parameters["@out_message"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_ticketdatatypeid", MySqlDbType.Int32));
                cmd.Parameters["@out_ticketdatatypeid"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_type", MySqlDbType.VarChar));
                cmd.Parameters["@out_type"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_workminutes", MySqlDbType.VarChar));
                cmd.Parameters["@out_workminutes"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_agentid", MySqlDbType.VarChar));
                cmd.Parameters["@out_agentid"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_tickedassignedid", MySqlDbType.Int32));
                cmd.Parameters["@out_tickedassignedid"].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(new MySqlParameter("@out_parentticketdataid", MySqlDbType.Int32));
                cmd.Parameters["@out_parentticketdataid"].Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                objMessage.Text = "<pre>" + cmd.Parameters["@out_message"].Value.ToString() + "</pre>";

                lnkReply.NavigateUrl = "Reply.aspx?id=" + Request.QueryString["id"] + "&d=" + Request.QueryString["d"];
                cmd.Dispose();
            } catch (MySql.Data.MySqlClient.MySqlException ex) {
                Debug.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            } finally {
                conn.Close();
            }
        }
        */

    }
}